# -*- coding: utf-8 -*-

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, ForeignKey, UniqueConstraint, Index, Text, DateTime
from sqlalchemy.orm import sessionmaker, relationship
from sqlalchemy import create_engine

engine = create_engine("mysql+pymysql://root:root@192.168.0.7:3306/51job", max_overflow=5)
Base = declarative_base()

# 创建表，岗位列表
class jobs(Base):
    __tablename__ = 'jobs'
    # {"station": "PHP程序员/PHP开发工程师（后端）", "job_detail_url": "https://jobs.51job.com/guangzhou-thq/115155388.html?s=01&t=0", "company": "广州学而好教育信息咨询有限公司", "address": "广州-天河区", "salary": "0.8-1万/月", "release_time": "08-06", "page": 1}
    id = Column(Integer, primary_key=True)
    station = Column(String(100))
    r_jobid = Column(Integer)
    job_detail_url = Column(String(255))
    company = Column(String(50))
    address = Column(String(50))
    salary = Column(String(50))
    release_time = Column(String(50))
    page = Column(String(50))
    add_time = Column(DateTime)

# 岗位详情
class job_detail(Base):
    __tablename__ = 'job_detail'
    id = Column(Integer, primary_key=True)
    station = Column(String(100))
    company = Column(String(100))
    r_jobid = Column(Integer)
    l_jobid = Column(Integer)
    # msg_1 = Column(String(150))

    address = Column(String(30))
    experience = Column(String(30))
    xueli = Column(String(30))
    people_num = Column(String(30))
    release_time = Column(String(30))

    tags = Column(String(150))
    job_info = Column(Text)
    contact_way = Column(String(255))
    company_info = Column(Text)
    add_time = Column(DateTime)

Base.metadata.create_all(engine)
#创建mysql操作对象
Session = sessionmaker(bind=engine)
session = Session()
